﻿using Jint;
using Jint.Runtime.Debugger;
using System;
using System.Collections.Generic;
using T.FAS.Runtime.Expression.Entity;
using T.FAS.Runtime.Expression.Service;
using T.FAS.Runtime.Expression.SGSPI;
using T.ServiceComponent.Kernel.Service;

namespace T.FAS.Runtime.Expression.SGPlugin
{
    [SGService]
    public class FASRExprService : ISGExprService
    {
        /// <summary>
        /// 执行调试
        /// </summary>
        /// <param name="expr"></param>
        /// <param name="inputParam"></param>
        /// <returns></returns>
        [SGService(ServiceID = "FASR-ExprDebugInternal")]
        public Dictionary<string, object> Debug(string expr, Dictionary<string, object> inputParam)
        {
            return ExprService.GetInstance.DebugExecute(expr, inputParam);
        }
        /// <summary>
        /// 是否有操作权限
        /// </summary>
        /// <returns></returns>
        public ExprResult JSExecute(string expr, Dictionary<string, object> inputParam)
        {
            return ExprService.GetInstance.JSExecute(expr, inputParam);
        }
        /// <summary>
        /// 是否有操作权限
        /// </summary>
        /// <returns></returns>
        public Dictionary<string, object> ExecutePlugin(string actionCode, Dictionary<string, object> param)
        {
            Dictionary<string, object> keyValuePairs = new Dictionary<string, object>();
            return keyValuePairs;
        }
        /// <summary>
        /// 表达式调试
        /// </summary>
        /// <returns></returns>
        public void DebugExpr(string expr, Dictionary<string, object> inputParam, string sessionID)
        {
            ExprService.GetInstance.DebugExpr(expr, inputParam, sessionID);
        }
        /// <summary>
        /// 停止调试
        /// </summary>
        /// <returns></returns>
        public void StopDebug(string sessionID)
        {
            ExprService.GetInstance.StopDebug(sessionID);
        }
        /// <summary>
        /// 继续调试
        /// </summary>
        /// <returns></returns>
        public void ContinueDebug(string sessionID, StepMode stepMode)
        {
            ExprService.GetInstance.ContinueDebug(sessionID, stepMode);
        }
        /// <summary>
        /// 获取调试信息
        /// </summary>
        /// <returns></returns>
        public DebugInfo GetDebugInfo(string sessionID)
        {
            return ExprService.GetInstance.GetDebugInfo(sessionID);
        }
    }
}
